package cn.edu.nankai.bookstore.controller.customer;

import cn.edu.nankai.bookstore.domain.po.Customer;
import cn.edu.nankai.bookstore.service.CustomerService;
import cn.edu.nankai.bookstore.service.impl.CustomerServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UpdateUserInfoServlet", value = "/UpdateUserInfoServlet")
public class UpdateUserInfoServlet extends HttpServlet {
    private CustomerService customerService = new CustomerServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Customer customer = (Customer) session.getAttribute("user");
        if(customer == null) return;
        String name = request.getParameter("name");
        String address = request.getParameter("address");
        String pwd = request.getParameter("pwd");
        customer.setName(name);
        customer.setAddress(address);
        customer.setPwd(pwd);
        Boolean status = customerService.modify(customer);
        response.getWriter().write(status.toString());
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
